<?php
/**
 * init.php
 *
 * @author: cnx7 <zysafe@live.cn> 2018-05-04
 */

if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: *');
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Allow-Headers: Content-Type,Access-Token');

    header('Content-Type: application/json');
    header('HTTP/1.1 204 No Content');
    return;
}

defined('ROOT_PATH') or define('ROOT_PATH', realpath(__DIR__ . '/..'));

# define
require ROOT_PATH . '/common/config/define.php';

# yii framework
require ROOT_PATH . '/vendor/autoload.php';
require ROOT_PATH . '/vendor/yiisoft/yii2/Yii.php';

Yii::setAlias('common', ROOT_PATH . '/common');

# app config
$config = yii\helpers\ArrayHelper::merge(
    require(ROOT_PATH . '/common/config/web.php'),
    require(ROOT_PATH . '/src/app/config/web.php')
);

(new yii\web\Application($config))->run();
